﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;

namespace Meraz.Core.Net
{
    public class Mailer : IMailer
    {
        public IMailerSettings Settings { get; set; }

        public Mailer(IMailerSettings settings) { Settings = settings; }

        public void Setup() { }

        public void Send(MailInfo mailInfo)
        {
            if (mailInfo.Message.To == null || mailInfo.Message.To.Count == 0)
                mailInfo.Message.To.Add( new MailAddress(Settings.From));

            if (mailInfo.Message.ReplyToList.Count == 0)
                mailInfo.Message.ReplyToList.Add(new MailAddress(Settings.ReplyTo));
            mailInfo.Message.From = new MailAddress(Settings.From);
            //Send the message.
            SmtpClient smtp = new SmtpClient();
            smtp.Send(mailInfo.Message);
        }
        public void SendAsync(MailInfo mailInfo)
        {
            mailInfo.Message.From = new MailAddress(Settings.From);
            //Send the message.
            SmtpClient client = new SmtpClient();
            client.SendAsync(mailInfo.Message, null);
        }
    }
}
